package com.example.javatwo.controller.cg.dwh;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.javatwo.pojo.cg.dwh.PrepaymentmainPojo;
import com.example.javatwo.pojo.cg.dwh.PrepaymentmaindetailPojo;

import com.example.javatwo.service.cg.dwh.FukuanService;

@Controller
public class FukuanController {
	
	@Autowired
	private FukuanService fukuanservice;
	
	
	/*public FukuanService getFukuanservice() {
		return fukuanservice;
	}

	public void setFukuanservice(FukuanService fukuanservice) {
		this.fukuanservice = fukuanservice;
	}*/

	@RequestMapping(value = "/fukuan",method = RequestMethod.GET)
	public String fukuan() throws Exception{
		return "cg/dwh/fukuan";
	}
	
	/**
	 * 查询主表预收款
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/chaxun")
	@ResponseBody
	public PageBean findchaxun(int page) throws Exception{
		int count = this.fukuanservice.count();
		Object pageobj = this.fukuanservice.findPrepaymentmainPojo(page);
		PageBean bean = new PageBean(count,page, pageobj);
		return bean;
	}
	
	/**
	 * 查询从表预收款
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/chaxuncongbioa",method = RequestMethod.GET)
	@ResponseBody
	public List<PrepaymentmaindetailPojo> findchaxuncong(String fundBillID) throws Exception{
		return this.fukuanservice.findPrepaymentmaindetailPojo(fundBillID);
	}
	
	/**
	 * 查询从表预收款
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/insertdwh",method = RequestMethod.POST)
	@ResponseBody
	public void insertzhubiaocongbiao(@RequestBody PrepaymentmainPojo pojo) throws Exception{
		 this.fukuanservice.insertrepaymentmainPojo(pojo);
	}
	
	/**
	 *删除   逻辑删除
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/dwhdelete")
	public void dwhDelete( String fundBillID) throws Exception{
		 this.fukuanservice.dwhDelete(fundBillID);
	}
	
	/**
	 *删除 
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/dwhdeletezhubiaocongbiao",method = RequestMethod.POST)
	public void dwhdeletezhubiaocongbiao(@RequestBody PrepaymentmainPojo pojo) throws Exception{
		
		 //删除之后在添加主表和从表
		 this.fukuanservice.dwhShanchuzhubiao(pojo.getFundbillid());
		 //添加主表和从表
		 this.fukuanservice.insertrepaymentmainPojo(pojo);
		 
	}
	
	/**
	 *审核
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/dwhshenhe")
	public void dwhshenhe(String fundBillID,double money,String gongyingshangID) throws Exception{
		this.fukuanservice.dwhShenhe(fundBillID);
		//剩余额度和期末预付款
		this.fukuanservice.dwhXiugaiGongyingshangJine(money, gongyingshangID);
	}
	
	/**
	 *反审核
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/dwhshenheFan")
	public void dwhshenheFan(String fundBillID,double money,String gongyingshangID) throws Exception{
		this.fukuanservice.dwhfansShenhe(fundBillID);
		//剩余额度和期末预付款
		this.fukuanservice.dwhXiugaiGongyingshangJineFan(money, gongyingshangID);
	}
	
	/**
	 *自动生成单号
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/dwhzidongdanhao")
	public String dwhzidongdanhao(String fundBilldate) throws Exception{
		String sd = this.fukuanservice.dwhZuidaDanhao(fundBilldate);
		System.out.println(sd);
		return sd;
	}
	
	
//	/**
//	 *剩余额度和期末预付款
//	 * @return
//	 * @throws Exception
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/dwhgongyingshang")
//	public void dwhgongyingshang(double money,String gongyingshangID) throws Exception{
//		this.fukuanservice.dwhXiugaiGongyingshangJine(money, gongyingshangID);
//	}
//	
//
//	/**
//	 *剩余额度和期末预付款
//	 * @return
//	 * @throws Exception
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/dwhgongyingshangFan")
//	public void dwhgongyingshangFan(double money,String gongyingshangID) throws Exception{
//		this.fukuanservice.dwhXiugaiGongyingshangJineFan(money, gongyingshangID);
//	}
	
}
